<div id="main-content" class="main-content container-fluid">
    <?php echo $this->Html->script('print'); ?>
    <!-- // sidebar --> 
    <?php echo $this->element('sidebar/pedidos'); ?>               
    <!-- // fin sidebar -->
    <!-- // contenido pricipal -->                                 
    <div id="page-content" class="page-content">  
        <section>
            <div class="row-fluid">
                <div class="span6 grider">
                    <div id="aImprimir">
                    <?php 
                    $totalCancelar1 = 0;
                    $totalCancelar2 = 0; 
                    $totalCancelar = 0;
                    ?>
                       <?php if(!empty($itemsllevar)): ?>
                        <h3><i class="aweso-icon-table"></i> Mesa: <?php echo $mesa; ?> <small>Mozo: <?php echo $mozo; ?></small></h3>                   
                        <table class="table boo-table table-striped table-content table-hover">
                            <colgroup>
                                <col class="col20"/>
                                <col class="col50"/>
                                <col class="col15"/>
                                <col class="col15"/>
                                <col class="col15"/>
                            </colgroup>
                            <caption>
                                Pedidos para llevar
                            </caption>
                            <thead>
                                <tr id="HeadersRow0">
                                    <th scope="col">No.</th>
                                    <th scope="col">Producto</th>
                                    <th scope="col">Cantidad</th>
                                    <th scope="col">P/U</th>
                                    <th scope="col">Costo</th>                                       
                                </tr>                        
                            </thead>                       
                            <tbody>
                                
                                <?php $totalAderezo = 0; ?>
                                <?php $i = 1; ?>
                                <?php $aderezosPedido = $itemsllevar; ?>
                                <?php foreach ($itemsllevar as $p): ?>
                                    <?php
                                    $numeroPizza = $p['Item']['nropizza'];
                                    ?>   
                                    <?php if ($p['Item']['aderezo_id'] == null && $p['Item']['insumo_id'] == null): ?>
                                        <tr id="DataRow0">
                                            <td><?php echo $i; ?></td>
                                            <td class="bold" style="width: 250px;"><?php echo $p['Producto']['nombre']; ?></td>
                                            <td>1</td>
                                            <td><?php echo round($p['Producto']['precio']); ?></td>
                                            <td style="text-align: right;">
                                            <?php echo number_format($p['Producto']['precio'],'2','.',','); ?>
                                            <?php $totalCancelar1 += $p['Producto']['precio']; ?>
                                            </td>                                                                 
                                        </tr>  
                                        <?php //debug($p); ?>                                
                                        <?php foreach ($aderezosPedido as $a): ?>
                                        <?php //debug($a); ?>
                                            <?php if (($a['Item']['insumo_id'] != null)&& ($a['Item']['producto_id'] == $p['Item']['producto_id'])): ?>
                                                <tr id="DataRow0">
                                                    <td>&nbsp;</td>
                                                    <td class="bold" style="width: 250px;">
                                                        
                                                        <?php 
                                                        if($a['Item']['aderezo_id']  == null)
                                                        {
                                                            echo 'Sin '.$a['Insumo']['nombre'].' en '.$a['Producto']['nombre'].' '.$a['Item']['nropizza'];
                                                        }elseif($a['Item']['aderezo_id'] != null){
                                                            echo 'Extra de '.$a['Insumo']['nombre'].' en '.$a['Producto']['nombre'].' '.$a['Item']['nropizza'];
                                                        }
                                                             
                                                        ?>
                                                        
                                                    </td>
                                                    <td>
                                                    &nbsp;
                                                    </td>
                                                    <td>
                                                
                                                    <?php
                                                    if($a['Item']['precio']  < 1)
                                                        {
                                                            $costo = $a['Item']['precio'];
                                                            echo ($costo *-1);
                                                        }else{
                                                            $costo= $a['Aderezo']['precio'];
                                                            echo $costo;
                                                        }?>
                                                  
                                                    </td>
                                                    <td style="text-align: right;">
                                                    <?php echo $a['Item']['precio']; ?>
                                                    <?php $totalCancelar1 += $costo; ?>
                                                    </td>                                          
                                                </tr>    
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    <?php endif; ?>
                                    <?php $i++; ?>
                                <?php endforeach; ?>
                            </tbody>
                            <tfoot>
                                <tr class="total" id="HeadersRow0">
                                    <th>Total</th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th class="text-right"><b>
                                            <?php
                                            echo $totalCancelar1;
                                            ?>
                                        </b></th>
                                </tr>
                            </tfoot>
                        </table>
                      <?php endif; ?>
                      <?php if(!empty($items)): ?>
                      <table class="table boo-table table-striped table-content table-hover">
                            <colgroup>
                                <col class="col20"/>
                                <col class="col50"/>
                                <col class="col15"/>
                                <col class="col15"/>
                                <col class="col15"/>
                            </colgroup>
                            <caption>
                                Pedidos para la mesa
                            </caption>
                            <thead>
                                <tr id="HeadersRow0">
                                    <th scope="col">No.</th>
                                    <th scope="col">Producto</th>
                                    <th scope="col">Cantidad</th>
                                    <th scope="col">P/U</th>
                                    <th scope="col">Costo</th>                                       
                                </tr>                        
                            </thead>                       
                            <tbody>
                                <?php $totalCancelar2 = 0; ?>
                                <?php $totalAderezo = 0; ?>
                                <?php $i = 1; ?>
                                <?php $aderezosPedido = $items; ?>
                                <?php foreach ($items as $p): ?>
                                    <?php
                                    
                                    if ($p['Item']['nropizza'] != null && $p['Item']['aderezo_id'] != null)
                                    {
                                        $totalCancelar2 +=$p['Aderezo']['precio'];
                                    }
                                    $numeroPizza = $p['Item']['nropizza'];
                                    ?>   
                                    <?php if ($p['Item']['nropizza'] == null): 
                                    $precio = $p['Item']['precio'];
                                    $totalCancelar2 += $precio;
                                    ?>
                                        
                                        <?php if($p['Item']['cantidad'] != 0): ?>
                                        <tr id="DataRow0">
                                            <td><?php echo $i; ?></td>
                                            <td class="bold" style="width: 250px;"><?php echo $p['Producto']['nombre']; ?></td>
                                            <td><?php echo round($p['Item']['cantidad']);?></td>
                                            <td><?php echo round($p['Producto']['precio']); ?></td>
                                            <td style="text-align: right;">
                                        
                                            <?php echo number_format($p['Item']['precio'],2,'.',','); ?>
                                            
                                            </td>                                                                 
                                        </tr>
                                        <?php endif; ?>  
                                        <?php //debug($p); ?>                                
                                        <?php foreach ($aderezosPedido as $a): ?>
                                        <?php //debug($a); ?>
                                            <?php if (($a['Item']['nropizza'] != null)&& ($a['Item']['producto_id'] == $p['Item']['producto_id'])): ?>
                                                <tr id="DataRow0">
                                                    <td><?php echo $p['Item']['nropizza']; ?></td>
                                                    <td class="bold" style="width: 250px;">
                                                        
                                                        <?php 
                                                        if($a['Item']['aderezo_id']  == null && $a['Item']['insumo_id'] != null)
                                                        {
                                                            echo 'Sin '.$a['Insumo']['nombre'].' en '.$a['Producto']['nombre'].' '.$a['Item']['nropizza'];
                                                        }elseif($a['Item']['aderezo_id']  != null){
                                                            echo 'Extra de '.$a['Insumo']['nombre'].' en '.$a['Producto']['nombre'].' '.$a['Item']['nropizza'];
                                                        }
                                                             
                                                        ?>
                                                        
                                                    </td>
                                                    <td>
                                                    &nbsp;
                                                    </td>
                                                    <td>
                                                    
                                                    <?php
                                                    if($a['Item']['precio']  < 1)
                                                        {
                                                            $costo = $a['Item']['precio']*-1;
                                                            echo number_format($costo,'2', '.', ',');
                                                        }else{
                                                            echo number_format($a['Aderezo']['precio'],'2','.',',');
                                                        }?>
                                                    
                                                    </td>
                                                    <td style="text-align: right;">
                                                    
                                                    
                                                    <?php echo number_format($a['Item']['precio'],'2','.',','); ?>
                                                    
                                                    </td>                                          
                                                </tr>    
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    <?php endif; ?>
                                    <?php $i++; ?>
                                <?php endforeach; ?>
                            </tbody>
                            <tfoot>
                                <tr class="total" id="HeadersRow0">
                                    <th>Total</th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th class="text-right">
                                       
                                       <?php echo number_format($totalCancelar2,'2','.',',');?>
                                       
                                    </th>
                                </tr>
                            </tfoot>
                        </table>
                      <?php endif; ?>
                      <?php $totalCancelar = $totalCancelar1 + $totalCancelar2; ?>
                      <table class="table boo-table table-striped table-content table-hover" id="tablaTotales">
                          <tr>
                              <td>Total a Cancelar</td>
                              <td><?php echo number_format($totalCancelar,'2','.',',') ?></td>
                          </tr>
                          <tr class="ocultar">
                             <td colspan="2">
                             NIT:.........................................
                             </td>
                          </tr>
                          <tr class="ocultar">
                             <td colspan="2">
                             NOMBRE:...................................
                             </td>
                          </tr>
                      </table>
                    </div>
                </div>
                <!-- //tabla -->       
                
                <div class="span4 grider">
                    <h3><i class="aweso-icon-table"></i> Acciones</h3>     
                    <a class="btn btn-large btn-orange" href="#" id="btCuenta"><i class="fontello-icon-publish"></i> IMPRIMIR CUENTA &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                    <div style="height: 10px;">&nbsp;</div> 
                    <?php 
                    if($estadoPedido < 3):?>                   
                    <a class="btn btn-large btn-red" href="#" id="btMuestraFacturar"><i class="fontello-icon-publish"></i> FACTURAR PEDIDO &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> 
                    <div style="height: 10px;">&nbsp;</div>
                     
                    <div id="muestraFacturar" style="display: none;">
                        <?php echo $this->Form->create('Pagos', array('action'=>'facturar')); ?>                        
                        <fieldset>                            
                            <label for="formA05">Nit: </label>
                            <?php echo $this->Form->text('nit', array('id'=>'nit', 'class'=>'input-block-level', 'placeholder'=>'Ingrese el nit')); ?>
                            <!--<input id="formA05" class="span6" type="text" placeholder="placeholder">-->                           
                            <!-- // form item -->

                            <legend>Detalles para facturar</legend>
                            <label for="formA04">Nombre: </label>
                            <div id="nombre">
                            <?php echo $this->Form->text('nombre', array('class'=>'input-block-level', 'placeholder'=>'Ingrese el nombre')); ?>
                            </div>
                            
                            <?php echo $this->Form->hidden('monto', array('value'=>$totalCancelar)); ?>
                            <?php echo $this->Form->hidden('pedido', array('value'=>$idPedido)); ?>
                            <!--<input id="formA04" class="input-block-level" type="text" placeholder="placeholder">-->
                            <!-- // form item -->                           
                            <label for="formA04">Efectivo: </label>
                            <?php echo $this->Form->text('efectivo', array('class'=>'input-block-level', 'id'=>'efectivo','placeholder'=>'Monto efectivo')); ?>
                            <label for="formA04">Cambio: </label>
                            <?php echo $this->Form->text('cambio', array('class'=>'input-block-level', 'id'=>'cambio','placeholder'=>'Monto efectivo','')); ?>
                            
                            <input type="submit" value="Facturar"/> 
                            </form>
                        </fieldset>
                        <hr/>
                    </div>                 
                    
                    <a class="btn btn-large btn-green" href="<?php echo $this->Html->url(array('controller'=>'Pagos', 'action'=>'pagar', $idPedido))?>"><i class="fontello-icon-publish"></i> PAGAR CUENTA</a>
                    <div style="height: 10px;">&nbsp;</div> 
                    
                    <a class="btn btn-large btn-turgu" href="<?php echo $this->Html->url(array('controller'=>'Pagos', 'action'=>'cancelarpedido', $idPedido))?>"><i class="fontello-icon-publish"></i> CANCELAR PEDIDO</a>
                   <?php endif; ?>
                    <script>
                        $("#btMuestraFacturar").click(function() {
                            //console.log('click');
                            $("#muestraFacturar").toggle("slow");
                        });
                        $("#nit").change(function(){
                            var nit = $("#nit").val();
                            console.log(nit);
                            $("#nombre").load('<?php echo $this->Html->url(array('controller'=>'pagos', 'action'=>'ajaxnombre')) ?>/'+nit);
                        });  
                        $("#efectivo").change(function(){
                            var efectivo = $("#efectivo").val();
                            var total = <?php echo $totalCancelar ?>;
                            var cambio = efectivo - total;
                            console.log(cambio);
                            $("#cambio").val(cambio);
                            
                        }
                        );
                        $(document).ready(function() {
                            $("#btImprimir").click(function() {
                                // windows.location("http://localhost/posvinto/posvinto/facturas/facturar3");
                                printElem({ leaveOpen: true, printMode: 'popup' });             
                                printElem({ overrideElementCSS: ['<?php echo $this->webroot; ?>css/boo.css'] });
                            });
                             $("#btCuenta").click(function() {
                                // windows.location("http://localhost/posvinto/posvinto/facturas/facturar3");
                                //printElem({ leaveOpen: true, printMode: 'popup' });             
                                printElem({ overrideElementCSS: ['http://localhost/pizza/app/webroot/css/imprimir.css'] });
                            });
                        });
                                
                        function printElem(options){
                            $('#aImprimir').printElement(options);
                        }
                    </script>
                </div>
                <!-- //tabla --> 
            </div>
    </div>
</section>
</div>	
<!-- // fin contenido principal --> 
</div>		
<!-- Sidebar -->
<?php //echo $this->element('menualmacenes') ?>
<!-- End Sidebar -->
<?php
//echo $this->element('menupedidos') ?>